package ar.uba.fi.algo3.titiritero.vista;

import java.awt.Color;
import java.awt.Dimension;
import java.awt.Graphics;
import java.awt.Image;

import ar.uba.fi.algo3.titiritero.SuperficieDeDibujo;
import ar.uba.fi.algo3.titiritero.controlador.CentralControlador;

public class Panel extends java.awt.Panel implements SuperficieDeDibujo {


	private static final long serialVersionUID = -5159188497592488407L;
	private Image imagen;

	public void paint(Graphics g) {
		g.drawImage(this.imagen, 0, 0, null);
	}
	
	public void actualizar() {
		this.repaint();
	}

	public void limpiar() {
		if(this.imagen == null)
			this.imagen = this.createImage(getSize().width, getSize().height);
		Graphics superficieParaDibujar =  this.imagen.getGraphics();
		superficieParaDibujar.setColor(Color.WHITE);// 
		superficieParaDibujar.fillRect(0, 0, this.getWidth(), this.getHeight());
		//this.setBackground(Color.RED);
	}

	public Graphics getBuffer(){
		return this.imagen.getGraphics();
	}
	
	public Panel(int ancho,int alto, CentralControlador unControlador){
		this(ancho, alto);
		this.addMouseListener(unControlador);
		this.addKeyListener(unControlador);
	}
	
	public Panel(int ancho,int alto){
		this.setPreferredSize(new Dimension(ancho, alto));
		this.setVisible(true);
	}

}
